import Vue from 'vue'
import VueRouter from 'vue-router'
// import Layout from '../views/layout/Layout.vue'

Vue.use(VueRouter)

let paths = '/'
let names = ''
const routes = [
 // {
 //   path: paths,
 //   name: names,
 //   // component: Layout,
 //   component: () => import('../views/' + names + '/' + names.charAt(0).toUpperCase() + names.slice(1)),
 // },
]

const router = new VueRouter({
 routes,
})



router.beforeEach((to, from, next) => {
 console.log(to)
 console.log(from)
let paths = to.path
 let names = to.path.slice(1)
 let ro = {
path: paths,
name: names,
component: () => import('../views/' + names + '/' + names.charAt(0).toUpperCase() + names.slice(1) + '.vue'),
 }
//  routes.push(ro)
let flag=router.getRoutes().some(item=>item.name==names)
if(flag){
 next()
}else{
    router.addRoute(ro)
    next({...ro,replace:true})

}
})

export default router